<?php
class ReminderUserData_Data {
	
	private $database;
	
	public function __construct(){
		$this->db = new MysqlImproved_Driver();
	}
	
	public function checkUsername($username){
		$this->db->connect();
		$username = $this->db->escape($username);
		$this->db->prepare(
				"
				SELECT
				username
				FROM
				users
				WHERE
				username = '$username'
				LIMIT
				1
				"
		);
		return $this->db->query();
	}
	
	public function checkEmail($email){
		$this->db->connect();
		$email = $this->db->escape($email);
		$this->db->prepare(
				"
				SELECT
				username
				FROM
				users
				WHERE
				username = '$email'
				LIMIT
				1
				"
		);
		return $this->db->query();
	}
	
	public function updatePasswordFromEmail($email, $password){
		$this->db->connect();
		$email = $this->db->escape($email);
		$password = $this->db->escape($passwordl);
		$this->db->prepare(
				"
				UPDATE
				`users`
				SET
				`password` = '?'
				WHERE
				email.users = '$email'
				;
				"
		);
		$this->db->bind_param($password);
		$this->db->query();
		return $this->db->update();
	}
	
	public function updatePasswordFromUsername($username, $password){
		$this->db->connect();
		$usename = $this->db->escape($username);
		$password = $this->db->escape($password);
		$this->db->prepare(
				"
				UPDATE
				`users`
				SET
				`password` = '?'
				WHERE
				username.users = '$username'
				;
				"
		);
		$this->db->query();
		return $this->db->update();
	}

	public function getUserDataFromEmail($email){
		$this->db->connect();
		$username = $this->db->escape($email);
		$this->db->prepare(
				"
				SELECT
				users.username,
				users.realname,
				users.password,
				users.email
				FROM
				users
				WHERE
				users.username = '$email'
				;
				"
		);
		$this->db->query();
		$data = $this->db->fetch('array');
		return $data;
	}
	
	public function getUserDataFromUsername($username){
		$this->db->connect();
		$username = $this->db->escape($username);
		$this->db->prepare(
				"
				SELECT
				users.username,
				users.realname,
				users.password,
				users.email
				FROM
				users
				WHERE
				users.username = '$username'
				;
				"
				);
		$this->db->query();
		$data = $this->db->fetch('array');
		return $data;
	}
}